package com.langxin.site.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.langxin.site.biz.PrecautionsBiz;
import com.langxin.site.model.PageInfo;
import com.langxin.site.model.PrecautionsInfo;
import com.langxin.site.model.vo.QueryVo;

/**
 * 注意事项
 * @author guqj
 *
 */
@Controller
@RequestMapping("zhuyisx")
public class PrecautionsAction {

	@Autowired
	private PrecautionsBiz   precautionsBiz;
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String precautions(Model model, QueryVo queryVo, PageInfo<PrecautionsInfo> pageInfo){
		precautionsBiz.queryPage(queryVo, pageInfo);
		if(pageInfo.getRecords() == null || pageInfo.getRecords().size() == 0){
			return "redirect:/zhuyisx";
		}
		model.addAttribute("pageInfo", pageInfo);
		model.addAttribute("type", queryVo.getType());
		model.addAttribute("hots", precautionsBiz.hot(4, queryVo.getType()));
		return "precaution/precaution_list.jsp";
	}
	
	/**
	 * 详情
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
	public String newsDetail(Model model, @PathVariable Integer id){
		PrecautionsInfo precautionsInfo = precautionsBiz.queryById(id);
		if(precautionsInfo == null){
			return "error/404.jsp";
		}
		model.addAttribute("precautionsInfo", precautionsInfo);
		model.addAttribute("hots", precautionsBiz.hot(4, precautionsInfo.getType()));
		return "precaution/precaution_detail.jsp";
	}
}
